package cn.shop.admin.entity.backUserModule;

import cn.hutool.core.lang.RegexPool;
import cn.shop.admin.entity.backRoleModule.BackRole;
import cn.shop.base.BaseEntity;
import cn.shop.utils.constant.Regular;
import cn.shop.validation.Save;
import cn.shop.validation.Update;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * 总后台用户表(BackUser)表实体类
 *
 * @author jzw
 * @since 2021-11-03 09:07:55
 */
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BackUser extends BaseEntity {

	private static final long serialVersionUID = 7854980516223949680L;

	/**
	 * 账户
	 */
	@NotBlank(message = "账户不能为空", groups = Save.class)
	@Pattern(regexp = Regular.ACCOUNT, message = Regular.ACCOUNT_MASSAGE, groups = Save.class)
	private String account;

	/**
	 * 密码
	 */
	@NotBlank(message = "密码不能为空", groups = Save.class)
	@Pattern(regexp = Regular.PASSWORD, message = Regular.PASSWORD_MASSAGE, groups = {Save.class, Update.class})
	@JsonProperty(access = Access.WRITE_ONLY)
	private String password;

	/**
	 * 姓名
	 */
	@TableField(condition = SqlCondition.LIKE)
	@Length(max = 10, groups = {Save.class, Update.class})
	@NotBlank(message = "姓名不能为空", groups = Save.class)
	private String name;


	@Pattern(regexp = RegexPool.MOBILE, message = "请输入正确手机格式", groups = {Save.class, Update.class})
	private String phone;

	/**
	 * 交易密码
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	private String transactionPassword;

	/**
	 * 是否为内置账户
	 */
	private Boolean initial;

	/**
	 * 是否启用
	 */
	private Boolean enable;

	@TableField(exist = false)
	private List<BackRole> roles;

}

